<?php

namespace App\Model;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Sms extends Authenticatable
{
    use Notifiable;

    protected $primaryKey = 'id';
    protected $table = 'sms';
    protected $fillable = [
        'mobile',
        'type',
        'ip',
        'code',
        'create_time'
    ];
/**/
    protected $casts = [
    ];

    const CREATED_AT = null;
    const UPDATED_AT = null;

    public function createDate($data){
        $data['create_time'] = time();
        return $this->insertGetId($data);

    }
    // 验证10分钟内 全部申请
    public function getSmsAll($mobile){
        $lists = $this->where('mobile',$mobile)
            ->where('create_time','>',(time()-600))
            ->orderBy('id','desc')
            ->limit(30)
            ->select('mobile','type','ip','create_time')
            ->get()->toArray();
        return $lists;
    }
    // 验证1分钟内 是否有重复申请
    public function existsMobile($mobile,$type){
        $isExists = $this->where('mobile',$mobile)
            ->where('type',$type)
            ->where('create_time','>',(time()-60))
            ->exists();
        if($isExists){
            return 1;
        }else{
            return 0;
        }
    }

    public  function fromDateTime($value){
        return strtotime(parent::fromDateTime($value));
    }
    /**/
}
